package com.example.umeng;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;

import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.controller.UMServiceFactory;
import com.umeng.socialize.controller.UMSocialService;
import com.umeng.socialize.media.QZoneShareContent;
import com.umeng.socialize.sso.QZoneSsoHandler;
import com.umeng.socialize.sso.UMQQSsoHandler;
import com.umeng.socialize.weixin.controller.UMWXHandler;

public class MainActivity extends AppCompatActivity {
//////
    private UMSocialService mController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mController = UMServiceFactory.getUMSocialService("com.umeng.share");
        mController.setShareContent("share");
        //微信分享需要apk的md5签名，否则无效
        UMWXHandler wxHandler = new UMWXHandler(MainActivity.this, "wx967daebe835fbeac",
                "5fa9e68ca3970e87a1f83e563c8dcbce");
        wxHandler.addToSocialSDK();

        UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(MainActivity.this,
                "100424468", "c7394704798a158208a74ab60104f0ba");
        qqSsoHandler.addToSocialSDK();

        QZoneSsoHandler qzhandler = new QZoneSsoHandler(MainActivity.this,
                "100424468", "c7394704798a158208a74ab60104f0ba");
        qzhandler.addToSocialSDK();
        QZoneShareContent shareContent = new QZoneShareContent();
        shareContent.setShareContent("sougou");
        shareContent.setTitle("u");
        shareContent.setTargetUrl("https://123.sogou.com/");
        mController.setShareMedia(shareContent);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            mController.getConfig().removePlatform(SHARE_MEDIA.RENREN,
                    SHARE_MEDIA.DOUBAN);
            mController.openShare(MainActivity.this, false);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}